Skip to content

Fix reference file logging to avoid logcat output - #12620

Open
simonrozsival wants to merge 1 commit into
mainfrom
simonrozsival-startup-gc-investigation
Open

Fix reference file logging to avoid logcat output#12620
simonrozsival wants to merge 1 commit into
mainfrom
simonrozsival-startup-gc-investigation

Conversation

@simonrozsival

Copy link
Copy Markdown
Member

Description

OSBridge::log_it() unconditionally wrote reference log lines to logcat even when gref=<file> or lref=<file> selected file output without the + logcat option. Large GC-bridge diagnostics consequently flooded logcat and caused messages to be dropped.

Only write the line to logcat when no file is available or logcat output was explicitly requested. File output remains unchanged. The shared CLR host source covers CoreCLR and NativeAOT.

Validation

  • Built src/native/native-clr.csproj for all configured Android ABIs.
  • Built src/native/native-nativeaot.csproj for all configured Android ABIs.
  • Validated on an arm64 Android emulator with gc,gref=<file>: reference traffic was written to the file, while logcat contained only the file-open diagnostic. All 780 weak-reference creations and promotions were preserved in the file.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings September 1, 2026 11:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

Review tier: Lite
Findings: 1 Low severity

New issues introduced by this change (1)
Severity Finding
Low severity src/​native/​clr/​host/​os-bridge.cc — 💡 suggestion — The comment about “skipping logcat when logging to file” is now misleading because…
What changed in this PR

This PR adjusts native CLR host reference logging to prevent GC bridge “gref/lref” traffic from flooding logcat when file-based reference logging is selected, while preserving existing file output behavior.

Changes:

  • Gate OSBridge::log_it() logcat writes so they occur only when no file is available (to == nullptr) or when logcat output was explicitly requested.
  • Keep file logging and stack-trace emission behavior intact for reference logging.
File Description
src/​native/​clr/​host/​os-bridge.cc Avoid unconditional logcat writes when reference logging is routed to a file unless logcat is explicitly enabled.

Comment thread src/native/clr/host/os-bridge.cc
@simonrozsival

Copy link
Copy Markdown
Member Author

/review

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Android PR Reviewer completed successfully!

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • azcliprod.blob.core.windows.net

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "azcliprod.blob.core.windows.net"

See Network Configuration for more information.

Generated by Android PR Reviewer for #12620

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Needs Changes

Findings: 0 errors · 0 warnings · 1 suggestion

The routing condition correctly preserves compact no-file logging, suppresses logcat for file-only reference logs, and retains explicit gref+/lref+ output. I left one inline suggestion for automated regression coverage.

CI build #1576487 is currently red: Windows > Build & Smoke Test failed while much of the matrix is still running. The Azure DevOps CLI was not authenticated in this environment, so I could not determine whether that failure is related; it needs to be triaged or cleared before merge.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • azcliprod.blob.core.windows.net

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "azcliprod.blob.core.windows.net"

See Network Configuration for more information.

Generated by Android PR Reviewer for #12620 · gpt56 · 105.9 AIC · ⌖ 15.7 AIC · ⊞ 25.7K
Comment /review to run again

void OSBridge::log_it (LogCategories category, std::string_view const& line, FILE *to, const char *const from, bool logcat_enabled) noexcept
{
log_writef (category, LogLevel::Info, "%.*s", static_cast<int>(line.length ()), line.data ());
if (to == nullptr || logcat_enabled) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 💡 Testing — This predicate is now the contract separating compact (gref-/lref-), file-only, and file-plus-logcat modes, but the regression is covered only by manual validation. Please consider adding a focused test that exercises the routing combinations—especially to != nullptr && !logcat_enabled alongside the + case—so a future refactor cannot silently restore the logcat flood or suppress explicitly requested output.

Rule: Regression coverage

@jonathanpeppers jonathanpeppers left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the overall function be rewritten to be a bit clearer:

	if (to == nullptr || logcat_enabled) {
		log_writef (category, LogLevel::Info, "%.*s", static_cast<int>(line.length ()), line.data ());
	}

	// We skip logcat here when logging to file is enabled because _write_stack_trace will output to logcat as well, if enabled
	if (to == nullptr) {
		if (logcat_enabled) {
			_write_stack_trace (nullptr, from, category);
		}

		return;
	}

I'm confused what is going on, now there are multiple if blocks checking the same values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants